import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:getx_scaffold/common/widgets/icon_x.dart';
import 'package:oramemo/common/styles/colors.dart';
import 'package:oramemo/common/utils/url_utils.dart';
import 'package:oramemo/generated/assets.dart';
import 'package:oramemo/pages/first/first_logic.dart';
import 'package:oramemo/pages/home/home_logic.dart';
import 'package:oramemo/pages/position/position_flutter_map_view.dart';
import 'package:oramemo/pages/transcription/ai_transcription/ai_transcription_logic.dart';

import 'call_logic.dart';

/// 圆形装饰组件
class CircleDecoration extends StatelessWidget {
  const CircleDecoration({
    Key? key,
    this.size = 69,
    this.color,
  }) : super(key: key);

  /// 圆形大小
  final double size;

  /// 圆形颜色，默认使用 CallLogic 中定义的颜色
  final Color? color;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 152.w,
      height: 152.h,
      child: Stack(
        children: [
          Positioned(
            left: 0,
            top: 0,
            child: Container(
              width: 152.w,
              height: 152.h,
              decoration: ShapeDecoration(
                color: Color(0xFFE5F3FF),
                shape: OvalBorder(),
              ),
            ),
          ),
          Positioned(
            left: 21.w,
            top: 21.h,
            child: Container(
              width: 110.w,
              height: 110.h,
              decoration: ShapeDecoration(
                color: Colors.white,
                shape: OvalBorder(),
              ),
            ),
          ),
          Positioned(
            left: 5.w,
            top: 5.h,
            child: Container(
              width: 141.w,
              height: 141.h,
              decoration: ShapeDecoration(
                shape: OvalBorder(
                  side:
                      BorderSide(width: 8.w, color: Color(0xFF9BD0FF)),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}

class PoisetionTip extends StatelessWidget {
  const PoisetionTip({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 337.w,
      height: 80.h,
      decoration: ShapeDecoration(
        color: Colors.white,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(16.r),
        ),
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Text(
            '位置信息',
            textAlign: TextAlign.center,
            style: TextStyle(
              color: Color(0xFF06164B),
              fontSize: 20.sp,
              fontFamily: 'Inter',
              fontWeight: FontWeight.w400,
            ),
          ),
          SizedBox(height: 6.h),
          Text(
            '仅SOS呼叫时接受位置信息',
            textAlign: TextAlign.center,
            style: TextStyle(
              color: Color(0xFF787979),
              fontSize: 16.sp,
              fontFamily: 'Inter',
              fontWeight: FontWeight.w400,
            ),
          ),
        ],
      ),
    );
  }
}

class CallPage extends StatelessWidget {
  const CallPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<FirstLogic>(builder: (logic) {
      final data = HomeLogic.to.state.currentDevice;
      return Container(
        padding:
            EdgeInsets.only(left: 15.w, top: 42.h, right: 15.w, bottom: 0.h),
        child: Column(
          children: [
            GestureDetector(
                onTap: () {
                  UrlUtil.launchTelURL(data?.device?.deviceTelnum ?? '');
                },
                child: IconX.image(Assets.positionCall,
                    width: 141.w, height: 141.h)),
            SizedBox(height: 27.h),
            if(true)
              PoisetionTip()
            else
            Expanded(
              child: Container(
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(16.r),
                        topRight: Radius.circular(16.r))),
                child: Column(
                  children: [
                    SizedBox(height: 27.h),
                    Text('设备位置',
                        style: TextStyle(
                            fontSize: 20.sp,
                            color: Colours.text,
                            fontWeight: FontWeight.w500)),
                    Row(
                      children: [
                        IconX.image(Assets.positionMapPosition,
                            width: 14.w, height: 14.h),
                        Text('${data?.device?.deviceAddress ?? '未知'}',
                            style: TextStyle(
                                fontSize: 14.sp,
                                color: Colours.text,
                                fontWeight: FontWeight.w500)),
                      ],
                    ),
                    SizedBox(height: 18.h),
                    Expanded(
                      child: Padding(
                        padding: EdgeInsets.symmetric(horizontal: 16.h),
                        child: ClipRRect(
                          borderRadius: BorderRadius.circular(16.r),
                          child: GestureDetector(
                              behavior: HitTestBehavior.opaque,
                              // 添加此行，确保只有 GestureDetector 响应点击
                              onTap: () {
                                Get.to(const PositionFlutterMapView());
                              },
                              child: const IgnorePointer(
                                  child: Stack(
                                alignment: Alignment.center,
                                children: [
                                  PositionFlutterMapView(isShowInfo: false),
                                  // Positioned(
                                  //   bottom: 15.h,
                                  //   child: Text('仅SOS呼叫时，才显示位置信息',
                                  //       style:
                                  //           TextStyle(fontSize: 16.sp, color: Colours.text, fontWeight: FontWeight.w500)),
                                  // )
                                ],
                              ))),
                        ),
                      ),
                    )
                  ],
                ),
              ),
            ),
          ],
        ),
      );
    });
  }
}
